package frame;

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ExerciseFrameTest {
	static WebDriver driver;
	@BeforeClass
	public static void setup(){
		driver = new FirefoxDriver();
		driver.get("http://www.compendiumdev.co.uk/selenium/frames");
	}
	@Before
	public void refresh(){
		driver.navigate().refresh();
	}
	@AfterClass
	public static void closeDriver(){
		driver.quit();
	}
	@Test
	public void verifyH1(){
		driver.switchTo().frame("content");
		driver.findElement(By.cssSelector("a[href='green.html']")).click();
		new WebDriverWait(driver,10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("h1[id='green']")));
		driver.findElement(By.cssSelector("a[href='content.html']")).click();
		String textOnH1 = driver.findElement(By.cssSelector("h1")).getText();
		new WebDriverWait(driver,10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("h1")));
		assertEquals("","Content",textOnH1);
	}
	@Test
	public void verifyIFrame(){
		driver.switchTo().frame("menu");
		driver.findElement(By.cssSelector("a[href='iframe.html']")).click();
		new WebDriverWait(driver,10).until(ExpectedConditions.titleContains("iFrame"));
		assertEquals("","HTML Frames Example - iFrame Contents",driver.getTitle());
		driver.switchTo().frame(0);
		
		driver.findElement(By.cssSelector("a[href='frames_example_5.html']")).click();
		new WebDriverWait(driver,10).until(ExpectedConditions.titleContains("5"));
		assertEquals("","Frameset Example Title (Example 5)",driver.getTitle());
		driver.switchTo().frame("content");
		driver.findElement(By.cssSelector("a[href='index.html']")).click();
		assertEquals("","Frameset Example Title (Example 6)",driver.getTitle());
	}
	}


